package view;

import java.awt.BorderLayout;
import java.awt.SystemColor;

import javax.swing.DefaultCellEditor;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.UIManager;

import java.awt.Color;

import org.jdesktop.swingx.JXTaskPane;

public class PanelKhoHang extends JPanel {
	private static final long serialVersionUID = 638230385226310121L;
	private JTable table;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;
	private JTextField textField_6;
	private JTextField txtNhpMHng;
	private boolean visible;
	private JPanel advanced;

	public PanelKhoHang() {
		setLayout(new BorderLayout(0, 0));

		JPanel panel_2 = new JPanel();
		add(panel_2, BorderLayout.NORTH);
		panel_2.setLayout(new BorderLayout(0, 0));

		JPanel panel = new JPanel();
		panel_2.add(panel, BorderLayout.NORTH);
		panel.setBorder(new TitledBorder(UIManager
				.getBorder("TitledBorder.border"),
				"Th\u00F4ng tin t\u00ECm ki\u1EBFm", TitledBorder.LEADING,
				TitledBorder.TOP, null, new Color(51, 153, 255)));
		panel.setLayout(new FormLayout(
				new ColumnSpec[] { FormFactory.DEFAULT_COLSPEC,
						FormFactory.RELATED_GAP_COLSPEC,
						ColumnSpec.decode("max(134dlu;default)"),
						FormFactory.RELATED_GAP_COLSPEC,
						FormFactory.DEFAULT_COLSPEC,
						FormFactory.RELATED_GAP_COLSPEC,
						FormFactory.DEFAULT_COLSPEC, },
				new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, }));

		JLabel btnNewButton = new JLabel("Tìm kiếm");
		panel.add(btnNewButton, "1, 1");

		txtNhpMHng = new JTextField();
		txtNhpMHng.addFocusListener(new FocusAdapter() {
			@Override
			public void focusGained(FocusEvent e) {
				txtNhpMHng.selectAll();
			}
		});
		txtNhpMHng.setText("Nhập mã hàng");
		panel.add(txtNhpMHng, "3, 1, fill, default");
		txtNhpMHng.setColumns(18);

		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setToolTipText("Tìm kiếm nâng cao");
		lblNewLabel.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				visible = !visible;
				advanced.setVisible(visible);
			}
		});
		lblNewLabel.setIcon(new ImageIcon(getClass().getResource(
				"/images/advan.png")));
		panel.add(lblNewLabel, "5, 1");

		JButton btnNewButton_2 = new JButton("");
		btnNewButton_2.setIcon(new ImageIcon(getClass().getResource(
				"/images/search.png")));
		panel.add(btnNewButton_2, "7, 1");

		advanced = new JPanel();
		advanced.setBorder(new TitledBorder(null,
				"T\u00ECm ki\u1EBFm n\u00E2ng cao", TitledBorder.LEADING,
				TitledBorder.TOP, null, SystemColor.textHighlight));
		panel_2.add(advanced, BorderLayout.CENTER);
		advanced.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),
				FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"), }, new RowSpec[] {
				FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC, }));

		JCheckBox chckbxNewCheckBox = new JCheckBox("Mã hàng");
		advanced.add(chckbxNewCheckBox, "1, 1");
		advanced.setVisible(false);

		textField_2 = new JTextField();
		advanced.add(textField_2, "3, 1");
		textField_2.setColumns(10);

		JCheckBox chckbxNewCheckBox_1 = new JCheckBox("Số lượng");
		advanced.add(chckbxNewCheckBox_1, "5, 1");

		textField_3 = new JTextField();
		advanced.add(textField_3, "7, 1");
		textField_3.setColumns(10);

		JCheckBox chckbxNewCheckBox_2 = new JCheckBox("Nhà cung cấp");
		advanced.add(chckbxNewCheckBox_2, "1, 3");

		textField_4 = new JTextField();
		advanced.add(textField_4, "3, 3");
		textField_4.setColumns(10);

		JCheckBox chckbxNewCheckBox_3 = new JCheckBox("Lô hàng");
		advanced.add(chckbxNewCheckBox_3, "5, 3");

		textField_5 = new JTextField();
		advanced.add(textField_5, "7, 3");
		textField_5.setColumns(10);

		JCheckBox chckbxNewCheckBox_4 = new JCheckBox("Tên hàng");
		advanced.add(chckbxNewCheckBox_4, "1, 5");

		textField_6 = new JTextField();
		advanced.add(textField_6, "3, 5");
		textField_6.setColumns(10);

		JCheckBox chckbxNewCheckBox_5 = new JCheckBox("Ngày nhập");
		advanced.add(chckbxNewCheckBox_5, "5, 5");

		textField_1 = new JTextField();
		advanced.add(textField_1, "7, 5");
		textField_1.setColumns(10);

		JXTaskPane taskPane = new JXTaskPane();
		taskPane.setCollapsed(true);
		panel_2.add(taskPane, BorderLayout.SOUTH);

		JPanel panel_3 = new PanelThietBiDetail();
		taskPane.add(panel_3, BorderLayout.CENTER);

		JPanel panel_1 = new JPanel();
		add(panel_1, BorderLayout.CENTER);
		panel_1.setBorder(new TitledBorder(null, "Danh sách hàng trong kho",
				TitledBorder.LEADING, TitledBorder.TOP, null,
				SystemColor.textHighlight));
		panel_1.setLayout(new BorderLayout(0, 0));

		JScrollPane scrollPane = new JScrollPane();
		panel_1.add(scrollPane, BorderLayout.CENTER);
		scrollPane
				.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
		scrollPane
				.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

		table = new JTable();
		table.setModel(new DefaultTableModel(new Object[][] {
				{ null, true, null, null, null, null, null },
				{ null, null, null, null, null, null, null },
				{ null, null, null, null, null, null, null },
				{ null, null, null, null, null, null, null },
				{ null, null, null, null, null, null, null }, }, new String[] {
				"STT", "M\u00E3 thi\u1EBFt b\u1ECB",
				"T\u00EAn thi\u1EBFt b\u1ECB", "S\u1ED1 l\u01B0\u1EE3ng",
				"\u0110\u01A1n gi\u00E1", "Nh\u00E0 cung c\u1EA5p",
				"Ng\u00E0y nh\u1EADp" }));
		table.getColumnModel().getColumn(0).setMaxWidth(45);

		JCheckBox check = new JCheckBox();
		DefaultCellEditor dc = new DefaultCellEditor(check);
		table.getColumnModel().getColumn(1).setCellEditor(dc);

		scrollPane.setViewportView(table);
	}
}
